package com.hkd.system.controller.sysuser;


import com.hkd.common.core.constants.HttpConstants;
import com.hkd.common.core.domain.R;
import com.hkd.system.domain.sysuser.dto.LoginDTO;
import com.hkd.system.domain.sysuser.dto.SysUserSaveDTO;
import com.hkd.system.service.sysuser.ISysUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@Slf4j
@Tag(name = "管理员接口")
@RequestMapping("/sysUser")
@RestController
public class SysUserController {
    @Autowired
    private ISysUserService sysUserService;

    /**
     * 超管登录
     * @param loginDTO 登录对象内部实现属性
     * @return String token
     */
    @PostMapping("/login")
    public R login(@RequestBody LoginDTO loginDTO){
        return  sysUserService.login(loginDTO.getUserAccount(), loginDTO.getPassword());
    }

    /**
     * 添加管理员
     * @param sysUserSaveDTO 添加对象内部实现属性
     * @return
     */
    @PostMapping("/add")
    @Operation(summary = "新增管理员",description = "根据信息新增管理员")
    public R add(@RequestBody SysUserSaveDTO sysUserSaveDTO){

        return sysUserService.add(sysUserSaveDTO);
    }

    /**
     * 获取用户昵称信息
     * @param token token
     * @return String nickName
     */
    @GetMapping("/info")
    public R getInfo(@RequestHeader(HttpConstants.AUTHENTICATION) String token){
        return sysUserService.getInfo(token);
    }

    /**
     * 退出登录
     * @param token
     * @return
     */
    @DeleteMapping("/logout")
    public R logout(@RequestHeader(HttpConstants.AUTHENTICATION) String token){
        return sysUserService.logout(token);
    }


}
